﻿namespace Microsoft.SharePoint.Client
{
    using System;
    using System.ComponentModel;

    [ScriptType("SP.FieldText", ServerTypeId="{47cba3a7-3327-4fa1-ac10-73a7a182fe05}")]
    public class FieldText : Field
    {
        [EditorBrowsable(EditorBrowsableState.Never)]
        public FieldText(ClientRuntimeContext Context, ObjectPath ObjectPath) : base(Context, ObjectPath)
        {
        }

        protected override bool InitOnePropertyFromJson(string peekedName, JsonReader reader)
        {
            string str;
            bool flag = base.InitOnePropertyFromJson(peekedName, reader);
            if (!flag && (((str = peekedName) != null) && (str == "MaxLength")))
            {
                flag = true;
                reader.ReadName();
                base.ObjectData.Properties["MaxLength"] = reader.ReadInt32();
            }
            return flag;
        }

        [Remote]
        public int MaxLength
        {
            get
            {
                base.CheckUninitializedProperty("MaxLength");
                return (int) base.ObjectData.Properties["MaxLength"];
            }
            set
            {
                if (base.Context.ValidateOnClient)
                {
                    if (value < 1)
                    {
                        throw ClientUtility.CreateArgumentException("value");
                    }
                    if (value > 0xff)
                    {
                        throw ClientUtility.CreateArgumentException("value");
                    }
                }
                base.ObjectData.Properties["MaxLength"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "MaxLength", value));
                }
            }
        }
    }
}

